﻿using LogLib;
using NewCapturerDemo.Config;
using NewCapturerDemo.DSLR;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Windows.Forms;

namespace NewCapturerDemo
{
    static class Program
    {
        private static CameraOption _option = new CameraOption();

        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main(string[] arg)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

			if (!LoadConfig())
			{
                MessageBox.Show("读取相机配置失败");
                return;
			}

            if (arg.Length > 0)
            {
				if (_option.IsUseDslr)
				{
                    Application.Run(new FormCapturerDSLR(_option,arg[0]));
                }
				else
				{
                    Application.Run(new FormCapturer(_option,arg[0]));
                }

                //MessageBox.Show("arg:" + arg[0]);
            }
            else
            {
                //Application.Run(new FormCapturer());
                //MessageBox.Show("no arg");
                if (_option.IsUseDslr)
                {
                    Application.Run(new FormCapturerDSLR(_option));
                }
                else
                {
                    Application.Run(new FormCapturer(_option));
                }
            }
        }

        static bool LoadConfig()
        {
            DirConfig.LoadConfig();
            if (!File.Exists(_option.ConfigFilePath))
            {
                _option.Save();
                Log.WriteAsync("镜头选项文件不存在.");
                return false;
            }
            if (_option.Load())
            {
                Log.WriteAsync("镜头选项加载成功.");
                return true;
            }
            else
            {
                Log.WriteAsync("镜头选项加载失败.");
                return false;
            }
            //string directory = ;
            //directory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase).Substring(6);
            // _player.SoundLocation = string.Format(@"{0}\wav\taking.wav", Application.StartupPath);
        }
    }
}
